<template>
  <div>
    <el-button type="primary" plain @click="dialogVisible = true;"
               style="position: absolute;left: 330px;top: 80px;">添加</el-button>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <el-input placeholder="请输入公司名称" v-model="brand.name" style="width: 300px"></el-input><br><br>
      <el-input placeholder="请输入所属公司" v-model="brand.company" style="width: 300px"></el-input><br><br>
      <el-input placeholder="请输入发源地" v-model="brand.headstream" style="width: 300px"></el-input><br><br>
      <el-input placeholder="请输入联系电话" v-model="brand.contact" style="width: 300px"></el-input><br><br>
      <el-input placeholder="请输入联系人" v-model="brand.the" style="width: 300px"></el-input>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false;add()">确 定</el-button>
  </span>
    </el-dialog>
    <br>
    <br>
    <el-table
      :data="list"
      border
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        style="width: 100%">
      </el-table-column>
      <el-table-column
        prop="name"
        label="品牌名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="company"
        label="公司名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="headstream"
        label="地区"
        width="180">
      </el-table-column>
      <el-table-column
        prop="contact"
        label="联系方式"
        width="180">
      </el-table-column>
      <el-table-column
        prop="the"
        label="联系人"
        width="180">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-edit"
            @click="dialogFormVisible=true;brands=scope.row"></el-button>
          <el-button
            size="mini"
            type="danger" icon="el-icon-delete"
            @click="del(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="品牌修改" :visible.sync="dialogFormVisible">
      <el-form :model="brands">
        <el-form-item label="编号">
          <el-input v-model="brands.id" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="名称" >
          <el-input v-model="brands.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="公司" >
          <el-input v-model="brands.company" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="公司地址" >
          <el-input v-model="brands.headstream" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="联系电话" >
          <el-input v-model="brands.contact" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="联系人" >
          <el-input v-model="brands.the" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="upd()">确 定</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
export default {
  name: "Brand",
  data(){
    return{
     list:[],
      dialogVisible:false,
      brand:{name:"",company:"", headstream:"",contact:"",the:""},
      dialogFormVisible:false,
      brands:{}
    }
  },
  created() {
   this.find()
  },
  methods:{
   find(){
     this.$http.post('/backservice/brand/find').then(data=>{
       this.list=data
     })
   },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    add(){
     this.$http.post('/backservice/brand/add',this.brand).then(data=>{
       if (data>0){
         this.find()
         alert("添加成功")
       }else {
         alert("添加失败")
       }
     })

    },
    upd(){
     this.dialogFormVisible = false
     this.$http.post('/backservice/brand/update',this.brands).then(data=>{
       if (data>0){
         this.find()
         alert("修改成功")
       }else {
         alert("修改失败")
       }
     })
    },
    del(row){
     this.$http.post('/backservice/brand/delete',{id:row.id}).then(data=>{
       if (data>0){
         this.find()
         alert("删除成功")
       }else {
         alert("删除失败")
       }
     })
    }

  }
}
</script>

<style scoped>

</style>
